<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "com.classes.Casemast, java.util.ArrayList, java.util.TreeMap, org.owasp.encoder.Encode" %>
<%@ page import = "com.mbbmap.util.Constants" %>
<%@ page import = "com.mbbmap.security.dao.*" %>
<%@ page import="com.mbbmap.app.manager.*" %>
<%@ page import="com.mbbmap.util.*" %>
<%@ page import = "java.net.URLEncoder" %>
<%@ include file="/jsp/map/include/user-dao.jsp" %>
<%

TreeMap<String, String> search = (TreeMap<String, String>) request.getAttribute("search");

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/map/include/html-meta.jsp" />
<title>MAYBANK</title>
</head>
<body>

<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->


<div class="row-fluid page">
	<div class="span12">

		<%
			String html = "<ul class='nav nav-tabs'>"
						+ 	"<li id='submission' class='active'><a href='" + request.getContextPath() + "/PendingApp.do?dispatch=init'>Pending for Submission</a></li>"
						+"</ul>";
						
			out.println(html);
		%>
		
		<form name="search_form" method="post" action="<%= request.getContextPath() + "/PendingApp.do?dispatch=init" %>">
			<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
			<div class="row-fluid form-horizontal search">
				<div class="span6">
					
					<div class="control-group">
						<label class="control-label">Reference No.</label>
						<div class="controls">
							<%
							html = "";
							if(search.containsKey("case_id") && search.get("case_id").length() > 0){
								html = search.get("case_id");
							}
							%>
							<input type="text" id="case_id" name="case_id" value="<%= html %>" />
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Registration Name</label>
						<div class="controls">
							<%
							html = "";
							if(search.containsKey("merchant_name") && search.get("merchant_name").length() > 0){
								html = search.get("merchant_name");
							}
							%>
							<input type="text" id="merchant_name" name="merchant_name" value="<%= html %>" />
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Application Type</label>
						<div class="controls">
							<select id="application_type" name="application_type">
							<% 
								html = "<option value=\"\"></option>"
									+ "<option value=\"New Application\">New Application</option>"
									+ "<option value=\"Extend Facility\">Extend Facility</option>"
									+ "<option value=\"e-Commerce/M2u\">e-Commerce/M2u</option>"
									+ "<option value=\"Additional Terminal/mPOS Reader\">Additional Terminal/mPOS Reader</option>";
								
								if(search.containsKey("application_type") && search.get("application_type").length() > 0){
									html = html.replace("value=\"" + search.get("application_type") + "\"", "value=\"" + search.get("application_type") + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
				</div>
				
				<div class="span6">
					
					<div class="control-group">
						<label class="control-label">Group</label>
						<div class="controls">
							<select id="group_code" name="group_code">
							<% 
								html = "<option value=\"\"></option>";
								for(SecGroupsDao ug : (ArrayList<SecGroupsDao>) request.getAttribute("groupList")){
									html += "<option value=\"" + EncryptionHelper.encrypt(ug.getGroupCode()) + "\">" + ug.getGroupName() + "</option>";
								}
								
								if(search.containsKey("group_code") && search.get("group_code").length() > 0){
									html = html.replace("value=\"" + EncryptionHelper.encrypt(search.get("group_code")) + "\"", "value=\"" + EncryptionHelper.encrypt(search.get("group_code")) + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
					
					<div class="control-group">
						<label class="control-label">User</label>
						<div class="controls">
							<select id="group_user" name="group_user">
							<%
								html = "<option value=\"\"></option>";
								for(SecUserDao u : (ArrayList <SecUserDao>) request.getAttribute("userList")){
									html += "<option value=\"" + EncryptionHelper.encrypt(u.getLogonId()) + "\">" + u.getUserName() + "</option>";
								}
								
								if(search.containsKey("group_user") && search.get("group_user").length() > 0){
									html = html.replace("value=\"" + EncryptionHelper.encrypt(search.get("group_user")) + "\"", "value=\"" + EncryptionHelper.encrypt(search.get("group_user")) + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Region</label>
						<div class="controls">
							<select id="reseller_location" name="reseller_location">
							<% 
								html = "<option value=\"\"></option>"
									+ "<option value=\"SABAH\">SABAH</option>"
									+ "<option value=\"SARAWAK\">SARAWAK</option>"
									+ "<option value=\"PERLIS\">PERLIS</option>"
									+ "<option value=\"KEDAH\">KEDAH</option>"
									+ "<option value=\"PULAU PINANG\">PULAU PINANG</option>"
									+ "<option value=\"PERAK\">PERAK</option>"
									+ "<option value=\"KELANTAN\">KELANTAN</option>"
									+ "<option value=\"TERENGGANU\">TERENGGANU</option>"
									+ "<option value=\"PAHANG\">PAHANG</option>"
									+ "<option value=\"SELANGOR\">SELANGOR</option>"
									+ "<option value=\"NEGERI SEMBILAN\">NEGERI SEMBILAN</option>"
									+ "<option value=\"MELAKA\">MELAKA</option>"
									+ "<option value=\"JOHOR\">JOHOR</option>"
									+ "<option value=\"WILAYAH PERSEKUTUAN\">WILAYAH PERSEKUTUAN</option>";
								
								if(search.containsKey("reseller_location") && search.get("reseller_location").length() > 0){
									html = html.replace("value=\"" + search.get("reseller_location") + "\"", "value=\"" + search.get("reseller_location") + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
					
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span12 btn-control search">
					<button id="search_submit" name="search_submit" type="submit" class="btn">Search</button>
					<button id="search_clear" name="search_clear" type="submit" class="btn">Clear</button>
				</div>
			</div>
		</form>
		
		<table class="tblDetails"><thead>
			<tr>
				<th>Group</th>
				<th>Reference No.</th>
				<th>Reseller Location</th>
				<th>By</th>
				<th>Created Date</th>
				<th>Status</th>
				<th>Application Type</th>
				<th>Registration No.</th>
				<th>Registration Name</th>
			</tr>
		</thead><tbody>
		<%
			int n = 0;
			for(Casemast c : (ArrayList<Casemast>) request.getAttribute("cArr")){
				String case_url = request.getContextPath() + "/NewApp.do?dispatch=init&";
				String encryptParam = "m_id=" + URLEncoder.encode(EncryptionHelper.encrypt(String.valueOf(c.getMerchant().getId()),ConfigManager.getInstance().get(Constants.ENCRYPTION_PASSPHRASE))) + "&c_id=" + URLEncoder.encode(EncryptionHelper.encrypt(String.valueOf(c.getId()),ConfigManager.getInstance().get(Constants.ENCRYPTION_PASSPHRASE)));
				case_url = case_url + encryptParam;
				
				html = "<tr class=" + (n % 2 > 0 ? "alt" : "even") + ">"
				+ "	<td>" + Encode.forHtml(c.getGroupName()) + "</td>"
				+ "	<td><a href=\"" + case_url + "\">" + Encode.forHtml(c.getReferenceNo()) + "</a></td>"
				+ "	<td>" + Encode.forHtml(c.getResellerLocation()) + "</td>"
				+ "	<td>" + Encode.forHtml(c.getCreatedBy()) + "</td>"
				+ "	<td>" + Casemast.formatCreatedDate("dd/MM/yyyy HH:mm", c.getCreatedDate()) + "</td>"
				+ "	<td>" + Encode.forHtml(c.getStatus()) + "</td>"
				+ "	<td>" + Encode.forHtml(c.getType()) + "</td>"
				+ "	<td>" + Encode.forHtml(c.getMerchant().getRegisteredNo()) + "</td>"
				+ "	<td>" + Encode.forHtml(c.getMerchant().getRegisteredName())  + "</td>"
				+ "</tr>";
				
				out.println(html);
				++n;
			}
		%>
		</tbody></table>
		
	</div>
</div>

<!-- Footer -->
<%@ include file="/jsp/common/Footer.jsp" %>	
<!-- End Footer -->

</body>
</html>